#!/usr/bin/env python
# encoding: utf-8
#
# written by Rostislav Mikheev, 2011

'''
wscript looks like 
def options(opt):
    opt.load('compiler_c sdl')

def configure(conf):
    conf.load('compiler_c sdl')

    # you can call check_freeimage with some parameters.
    # It's optional on Linux, it's 'mandatory' on Windows if
    # you didn't use --fi-path on the command-line

    # conf.check_freeimage(path='FreeImage/Dist', fip=True)

def build(bld):
    bld(source='main.cpp', target='app', use='SDL')
'''

from waflib import Utils
from waflib.Configure import conf

def options(opt):
	opt.add_option('--sdl-path', type='string', default='', dest='fi_path',
		help='''path to the SDL directory''')

@conf	
def check_sdl(self, path=None, fip=False):
    self.start_msg('Checking SDL')
    if not self.env['CXX']:
        self.fatal('you must load compiler_cxx before loading sdl')
    platform = Utils.unversioned_sys_platform()
	
	path = path or ''


	if platform == 'win32':
		conf.check_cc(lib=["SDL", "SDLmain"], path=path, mandatory=1)
		libs = ['SDL', 'SDLmain']
	else
		conf.check_cc(lib="SDL", path=path, mandatory=1)	
		libs = ['SDL']		
	
	self.env['INCLUDES_SDL'] = path
	self.env['LIBPATH_SDL'] = path
	

    if platform == 'win32':
        self.env['LIB_SDL'] = libs
    else:
        self.env['LIB_SDL'] = [i.lower() for i in libs]
    self.end_msg('ok')

def configure(conf):
	check_sdl(conf.options.sdl_path)
